<?php 
      session_start();
        if(!$_SESSION['log']){session_destroy();
        echo "<meta http-equiv='refresh' content='1;url=index.php'>";
      }
    
      ?>

<!DOCTYPE HTML SYSTEM>
<html>
<head>
<title>Capacity</title>
</head>
<body>
<a href="index.php">1. krok</a>
<a href="form2.php">2. krok</a>
<a href="form3.php">3. krok</a>
<a href="form4.php">4. krok</a>
<a href="out.php">5. krok</a>


    <form action="form3.php" method="get">


	<br/><br/>

	<label for="doors"> Pocet dveri (zadejte 3,4,5) </label>
	<input type="text" id="doors" name="doors" value="<?php echo $_GET['doors'];?>">
  	<label for="colour"> Barva (zadejte Cervena,Zluta,Zelena) </label>
	<input type="text" id="colour" name="colour" value="<?php echo $_GET['colour'];?>">
		


	<input type="submit" value="Next">
</form>
</body>
<html>


         <?php
$con=mysql_connect("localhost","reimemic","kee7baef");
// Check connection
if (!$con)
  {
  echo "Failed to connect to MySQL: " . mysql_connect_error();
  }

// Create database
mysql_select_db("reimemic");


include("Validator.php");
	 if (!empty($_GET)){
	$pole = array();
   $name =mysql_query("SELECT * FROM TrololoDvere WHERE 1", $con) ; 			                                                 
while ($current=mysql_fetch_array($name)){
$cmp=strcmp($current["Dvere"],$_GET['doors']);
   if($cmp==0){
   $dvere=$_GET['doors'];
   $cenadvere=$current["Cena"];
    $true=1;}
   else if(($cmp!=0 && true!=1)|| strlen($_GET['doors'])<1){
   	$pole['doors'] = 'Zadan spatny pocet dveri';}
    
    }
 $name =mysql_query("SELECT * FROM TrololoBarva WHERE 1", $con) ; 			                                                 
while ($current=mysql_fetch_array($name)){
$cmp=strcmp($current["Barva"],$_GET['colour']);
   if($cmp==0){
   $barva=$_GET['colour'];
   $cenabarva=$current["Cena"];
    $true=1;}
    else if(($cmp!=0 && true!=1)|| strlen($_GET['colour'])<1){
   	$pole['colour'] = 'Zadana spatna barva';}
    
    }
    }
	
  if (isset($pole)){
	if (!empty($pole)){

	
		foreach ($pole as $a){
			echo "<div>  " . $a . "</div><br/>";
		}

	}
  else{
    
     echo"$barva";
  $_SESSION['doors']=$dvere;
 
  $_SESSION['cenadvere']=$cenadvere;
   $_SESSION['colour']=$barva;
 
  $_SESSION['cenabarva']=$cenabarva;


       echo "<meta http-equiv='refresh' content='1;url=form4.php'>";
  }
  }
